<script setup>
import {defineProps} from "vue";
import {reactive,ref} from "vue";
const {PopShow, message,confirmClick} = defineProps([ 'popShow','message','confirmClick'])

const editData = reactive({
  title: message.title,
  price: message.price,
  id: message.id
})

const ruleFromRef = ref(null)
// 确认按钮提交
const onSubmitFrom =async (val)=>{
  if(!val){
    return
  }
  await val.validate((valid,fields)=>{
    if(valid) {
      confirmClick({title:editData.title,price:editData.price,id:editData.id})

    }else{
      console.log('error submit!',fields)
    }
  })

}
</script>

<template>
  <el-dialog
  title="编辑"
  v-model="PopShow"
  width="30%"
  align-center
  :show-close="false"
  >
    <el-form :model="editData" ref="ruleFromRef">
<!--      标题-->
      <el-form-item label="课程标题" prop="title" required>
        <el-input v-model="editData.title" />
      </el-form-item>
<!--      价格-->
      <el-form-item label="课程价格" prop="price" required>
        <el-input v-model="editData.price" />
      </el-form-item>
<!--按钮-->
      <el-form-item >
        <el-button @click="confirmClick('cancel')">取消</el-button>
        <el-button type="primary" @click="onSubmitFrom(ruleFromRef)">确认</el-button>
      </el-form-item>

    </el-form>
</el-dialog>
</template>

<style scoped lang="less">
.el-dialog{
  z-index: 30;
  width: 500px;
  height: 500px;
  background-color: #409eff;
}
:deep(.el-form-item__content){
  justify-content: center;
}
</style>